<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>编辑项目</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">

<!-- 百度地图推荐 -->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/common.css">
<link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="js/zTree_v3/css/metroStyle/metroStyle.css" >

<script src="js/jquery-1.11.1.js"></script>
<script src="js/select2/select2.min.js"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=vhpkslLjEeHY3WQMh5ndk6aeyb0NmytI"></script>
<script type="text/javascript" src="js/zTree_v3/js/jquery.ztree.core.min.js" ></script>
<script type="text/javascript" src="js/zTree_v3/js/jquery.ztree.excheck.min.js" ></script>
<script src="static/p_project/project-edit.js" ></script>
<script type="text/javascript" src="js/form.js"></script>

<style type="text/css">
html {
	height: 100%
}

body {
	height: 100%;
	margin: 0px;
	padding: 0px
}
#deptTree{
	display: none;
	margin:0 327px 0 50px;
	background-color: #eee;
	height: 140px;
	overflow-y: auto;
	overflow-x: hidden;
}

</style>
<script type="text/javascript">
	
	//管理隶属节点数据
	var zNodes=${requestScope.orgDeptList};

	$(function() {
		initS2();
		//初始化表单
		mySubmit("projectEditForm", initProjectEditData, projectEditCallback);
		initBdMap();
		
	});
	//2
	function initBdMap(){
		var map = new BMap.Map("baidumap"); 
		map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
		var point = new BMap.Point(${requestScope.projectInfo.projectCoordinate }); 
		var marker = new BMap.Marker(point);//创建标注
		
		// 创建地理编码实例      
		var myGeo = new BMap.Geocoder();      
		// 根据坐标得到地址描述    
		myGeo.getLocation(new BMap.Point(${requestScope.projectInfo.projectCoordinate }), function(result){
		    if (result){ 
		    var label=new BMap.Label(result.address+"<br/>${requestScope.projectInfo.projectName }",{offset:new BMap.Size(20,-10)});
		    	label.setStyle({
		    	    padding: '4px',
					border: '1px solid "#ff8355"',
					borderRadius: "5px"
					});     
		    	marker.setLabel(label);
		    }      
		});
		
		map.centerAndZoom(point, 15);
		map.addOverlay(marker);//添加标注到地图中
	}
	
	function initS2(){
		var $s2 = $("#projectType").select2();
		$s2.val("${requestScope.projectInfo.projectType }").trigger('change')
	}
	  
	//关闭当前layer
	function closeThis(){
		parent.layer.closeAll();
	}
	
	var pStatus=0;
	function zhuxiaoP(val){
		pStatus = val;
		$("#projectEditForm").submit();
	}
	var pid='${requestScope.projectInfo.id}';
	function initProjectEditData(){
		var projectName=$("#projectName").val();
		var projectType=$("#projectType").val();
		var projectCoordinate=$("#projectCoordinate").val();
		var sarr=new Array();
		
		$.each(arrDept,function(i,v){
			sarr.push(v.id);
		});
		
		var result;
		if(projectName==""){
			result=null;
			alert("请输入项目名称!");
		}else if(projectCoordinate==""){
			result=null;
			alert("请输入坐标!");
		}else if(sarr.length<1){
			result=null;
			alert("请选择管理隶属!");
		}else{
			result= {
				id:'${requestScope.projectInfo.id}',
				deptCorr:sarr,
				projectName:projectName,
				projectType:projectType,
				projectCoordinate:projectCoordinate,
				projectStatus:pStatus
			};
		}
		return result;
	}
	
	function projectEditCallback(data,success){
		var msg="";
		pStatus=0;//提交之后将操作字段更改回来
		if(data.status=="-2"){
			parent.layer.alert("项目名已经存在",{
				offset:'30%'
			});
			return;
		}
		
		if(data.status=="0"){
			msg="修改成功";
		}else{
			msg="注销成功";
		}
		parent.layer.alert(msg,{
			offset:'30%'
		},function(){
			parent.location.reload();
		});
	}
	
</script>


</head>

<body style="padding:30px;">
	<div style="width: 100%;height: 100%;">
		<form id="projectEditForm" method="post" class="form-horizontal"
			action="projectInfo/editProjectInfo">
			<div class="form-group">
				<label for="projectType">项目类型</label> <select id="projectType"
					style="width:64%;">
					<option value="行政办公" selected="selected">行政办公</option>
					<option value="居住场所">居住场所</option>
					<option value="商业综合">商业综合</option>
					<option value="教育场所">教育场所</option>
					<option value="文博场所">文博场所</option>
					<option value="交通枢纽">交通枢纽</option>
					<option value="养老医疗">养老医疗</option>
					<option value="工业园区">工业园区</option>
				</select>
			</div>
			<div class="form-group">
				<label for="projectBtn">管理隶属</label>
				<input type="text" id="deptCorr" name="deptCorr" style="width: 64%;display: inline-block;cursor:pointer;" placeholder="点击选择..." readonly="readonly" class="form-control" >
				<ul id="deptTree" class="ztree"></ul>
			</div>
			<div class="form-group">
				<label for="projectName">项目名称</label> <input type="text"
					value="${requestScope.projectInfo.projectName }"
					style="width: 64%;display: inline-block;" class="form-control"
					id="projectName" placeholder="">
				<span style="color:#f00;display: none;" >*名称已存在</span>
			</div>
			<div class="form-group">
				<label for="projectAddress">项目地址</label> <input type="text"
					style="width: 64%;display: inline-block;"
					value="${requestScope.projectInfo.projectCoordinate }"
					class="form-control" id="projectCoordinate"
					placeholder="点击选取坐标后复制到此..."> <a
					href="http://api.map.baidu.com/lbsapi/getpoint/index.html"
					target="_blank">选取坐标</a>
			</div>
			<!-- 公共产权人功能暂时去掉 -->
			<%-- <div class="form-group">
				<label>产权人唯一</label>
				<c:if test="${requestScope.projectInfo.onlyProperty==0 }">
					<span class="mingcheng"style="width: 50px;"><input type="radio"value="0" name="onlyProperty" checked="checked" disabled="disabled">是</span> 
					<span class="mingcheng" style="width: 50px;"><input type="radio" value="1" name="onlyProperty" disabled="disabled">否</span>
				</c:if>
				<c:if test="${requestScope.projectInfo.onlyProperty!=0 }">
					<span class="mingcheng"style="width: 50px;"><input type="radio"value="0" name="onlyProperty" checked="checked" disabled="disabled">是</span> 
					<span class="mingcheng" style="width: 50px;"><input type="radio" value="1" name="onlyProperty"  checked="checked" disabled="disabled">否</span>
				</c:if>
				<span id="msg" style="color:red">*</span>
			</div> --%>
			<div class="form-group">
				<button type="submit" class="btn btn-danger"
					style="margin-left: 52px;">保存修改</button>
				&nbsp;&nbsp;
				<button type="button" onclick="zhuxiaoP(1)" class="btn btn-default">注销项目</button>
			</div>
		</form>
		<div id="baidumap" style="width:1000px;height: 400px;"></div>
	</div>
</body>
</html>
